<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateCommodityActivitiesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('commodity_activities', function (Blueprint $table) {
            $table->id();
            $table->char('numbering', 6)->unique()->default('')->comment('编号');
            $table->bigInteger('commodity_id')->index()->comment('关联的商品');
            $table->tinyInteger('type')->default(1)->comment('活动类型; 1:今日直播 2:好评返团');
            $table->timestamp('panic_buying_start_time')->default(DB::raw('CURRENT_TIMESTAMP'))->index()->comment('抢购开始时间');
            $table->timestamp('panic_buying_end_time')->default(DB::raw('CURRENT_TIMESTAMP'))->index()->comment('抢购结束时间');
            $table->tinyInteger('sort_id')->default(0)->comment('排序号');
            $table->string('live_broadcast_url')->default('')->comment('直播地址');
            $table->text('live_broadcast_information')->nullable()->comment('直播信息');
            $table->text('desc')->nullable()->comment('详情文字');
            $table->integer('freight')->default(0)->comment('运费 单位(分)');
            $table->integer('free_shipping_minimal')->default(0)->comment('免邮:最少几件包邮(大于这个数包邮,零为没有限制)');
            $table->integer('free_shipping_maximum')->default(0)->comment('免邮:最多几件包邮(小于这个数包邮,零为没有限制)');
            $table->timestamp('after_sale_deadline')->nullable()->comment('售后截止时间');
            $table->timestamp('estimated_delivery_time')->nullable()->comment('预计发货时间');
            $table->tinyInteger('status')->default(2)->comment('状态; 1:上架 2:下架');
            $table->tinyInteger('locking')->default(1)->comment('状态; 1:激活 2:锁定');

            $table->tinyInteger('push_setting')->default(1)->comment('推送设置; 1:不推送 2:立即推送 3:定时推送 4:每日推送');
            $table->date('specify_the_push_date')->nullable()->comment('指定推送的日期; (push_setting) 3:年月日');
            $table->time('specify_the_push_time')->nullable()->index()->comment('指定推送的时间; (push_setting) 4:每日推送时间');
            $table->timestamp('last_push_time')->nullable()->comment('最后一次推送时间');

            $table->unsignedInteger('address_purchase_restriction')->default(0)->comment('同一地址限购数量; 0 为不限制');

            $table->timestamps();
            $table->softDeletes();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('commodity_activities');
    }
}
